<template>
  <div>
    <vxe-modal v-model="isVisiable" width="50vw" show-footer destroy-on-close :mask="false">
      <template #title>
        <span class="text-bold">阴性结果录入</span>
      </template>
      <template #default>
        <div style="height: 45vh" :class="resultIsDisabled() ? 'no-edit' : ''">
          <vxe-form :data="bacTestResultForm" title-width="85px">
            <vxe-form-gather span="8">
              <vxe-form-item title="样本号" field="sampleNo" span="24">
                <template #default="params">
                  <vxe-input v-model="params.data.sampleNo" type="text" disabled placeholder="样本号" clearable></vxe-input>
                </template>
              </vxe-form-item>
            </vxe-form-gather>
            <vxe-form-gather span="8">
              <vxe-form-item title="操作时间" field="operateDate" span="24" :item-render="{}" title-overflow="ellipsis">
                <template #default="params">
                  <vxe-input v-model="params.data.operateDate" type="datetime" placeholder="操作时间" clearable></vxe-input>
                </template>
              </vxe-form-item>
            </vxe-form-gather>
            <vxe-form-gather span="8">
              <vxe-form-item title="操作人" field="operateUserNo" span="24" :item-render="{}" title-overflow="ellipsis">
                <template #default="params">
                  <vxe-input v-model="params.data.operateUserNo" type="text" disabled placeholder="操作人" clearable></vxe-input>
                </template>
              </vxe-form-item>
            </vxe-form-gather>
            <vxe-form-gather span="24">
              <vxe-form-item title="鉴定结果" span="24">
                <template #title>
                  <span style="color: red">鉴定结果</span>
                </template>
                <template #default="params">
                  <VxePulldownSelectionByDictType v-if="isDescOptionResultFlag" :isChild="false" :isPage="true" :displayTexts="['germNa']" :displayTextObj="params.data.germNa ? params.data.germNa : ''" :tableColumn="[
                      { title: '#', type: 'seq', width: '30' },
                      { title: '微生物代号', field: 'germNo' },
                      { title: '名称', field: 'germNa' }
                    ]" :aimKeys="[
                      { aimKey: 'germNo', rowKey: 'germNo' },
                      { aimKey: 'germNa', rowKey: 'germNa' }
                    ]" :url="'/bac/germ/dict/getGermsByParams'" :dictTypeCode="'germType'" @confirmClick="SelectRowClick" />
                  <VxePulldownSelectionWithNa v-else style="width: 100%" :isChild="false" :url="'/api/bac/bac-desc-option/findBacDescOptionList'" @confirmClick="SelectRowClick" :tableColumn="[
                      { type: 'seq', title: '#', width: '30px' },
                      { field: 'optNa', title: '名称' },
                      { field: 'optNo', title: '编码' }
                    ]" :aimKeys="[{ aimKey: 'germNa', rowKey: 'optNa' }]" :displayTexts="['germNa']" :displayTextObj="params.data.germNa ? params.data.germNa : ''" />
                </template>
              </vxe-form-item>
            </vxe-form-gather>
            <vxe-form-gather span="24">
              <vxe-form-item title="结果描述" field="testResult" span="24" :item-render="{}" title-overflow="ellipsis">
                <template #default="params">
                  <vxe-textarea v-model="params.data.testResult" placeholder="结果描述" :autosize="{ minRows: 8, maxRows: 16 }" resize="vertical" @focus="showTypeCodeDrawer(params.data, 'xjpymsjg')" class="xjpymsjg"></vxe-textarea>
                </template>
              </vxe-form-item>
            </vxe-form-gather>
            <vxe-form-gather span="24">
              <vxe-form-item title="专家评语" field="descText" span="24" :item-render="{}" title-overflow>
                <template #default="params">
                  <vxe-textarea v-model="params.data.descText" placeholder="专家评语" :autosize="{ minRows: 8, maxRows: 16 }" resize="vertical" @focus="showTypeCodeDrawer(params.data, 'xjpyzjpy')" class="xjpyzjpy"></vxe-textarea>
                </template>
              </vxe-form-item>
            </vxe-form-gather>
          </vxe-form>
        </div>
      </template>
      <template #footer>
        <vxe-toolbar>
          <template #buttons> </template>
          <template #tools>
            <vxe-button type="text" class="button-white" @click="cancelEvent">取消</vxe-button>
            <vxe-button type="text" class="button-blue" @click="confirmEvent" :disabled="resultIsDisabled()">确定</vxe-button>
          </template>
        </vxe-toolbar>
      </template>
    </vxe-modal>
  </div>
  <BacFormEditDrawer ref="diagnosTempDrawerRef" @sltDiagnosTempInfo="selectDiagnosTempInfo"> </BacFormEditDrawer>
</template>

<script setup lang="ts">
import { ref, reactive, computed, getCurrentInstance, defineProps } from 'vue';
import { formatDateTime, IsEmpty } from '@/utils/common';
import { Splitpanes, Pane } from 'splitpanes';
import VxePulldownSelectionWithNa from '@/components/VxePulldownSelectionWithNa.vue';
import VxePulldownSelectionByDictType from '@/components/VxePulldownSelectionByDictType.vue';
import BacFormEditDrawer from './BacFormEditDrawer.vue';

let isDescOptionResultFlag = ref(false); /**是否描述性结果，默认添加阴性结果 */
let { proxy }: any = getCurrentInstance();
let diagnosTempDrawerRef = ref(null);
let isVisiable = ref(false);
let wkflwList: any[] = reactive([
  { code: '001', wk: '一般细菌及药敏鉴定方案流程' },
  { code: '002', wk: '支原体及药敏鉴定方案流程' },
  { code: '003', wk: '病毒及药敏鉴定' },
  { code: '004', wk: '寄生虫及药敏鉴定' }
]); /**流程方案集合 */
let wkflwNodeList: any[] = reactive([
  { code: '001', node: '培养' },
  { code: '002', node: '染色' },
  { code: '003', node: '观察形态' },
  { code: '004', node: '药敏试验' },
  { code: '005', node: '结论报告' }
]); /**流程方案节点集合 */

const props = defineProps({});
const wkflwRef = ref(null); /**流程方案列表对象 */
//const wkflwNodeRef = ref(null);/**流程方案节点列表对象 */

let labMainInfoObj: any = reactive({});
let bacTestResultForm: any = reactive({}); /**细菌鉴定结果表单对象 */

defineExpose({
  showModal /**打开选择方案的弹窗 */,
  editShowModal /**页面编辑/切换显示隐藏 */
});
/**流程方案单元格点击事件 */
function wkflwClick({ row, rowIndex }) {
  wkflwRef.value?.setRadioRow(row);
}
/**流程方案行单选按钮选中事件 */
function setSelectRow(row) {
  wkflwRef.value?.setRadioRow(row);
}
/**页面初始化/切换显示隐藏 */
function showModal(labmaininfo, isYangXResult = false) {
  isDescOptionResultFlag.value = isYangXResult;
  //查询当前信息的所有的血培养结果记录

  isVisiable.value = true;
  Object.assign(labMainInfoObj, labmaininfo);
  const userInfo = localStorage.getItem('userInfo');
  const userInfoObj = JSON.parse(userInfo);
  Object.assign(bacTestResultForm, {
    id: null,
    wkFlwId: '',
    isolateNum: null,
    germNo: null,
    germNa: null,
    testResult: null,
    resiPhenNa: '',
    urinColoCount: null,
    bacRate: null,
    infeSiteNa: '',
    operateDate: formatDateTime(new Date(), 'yyyy-MM-dd hh:mm:ss'),
    operateUserNo: userInfoObj ? userInfoObj.realname : '',
    sampleda: formatDateTime(labMainInfoObj.sampleda, 'yyyy-MM-dd hh:mm:ss'),
    rptGroup: labMainInfoObj.rptGroup,
    sampleNo: labMainInfoObj.sampleNo,
    maininfoId: labMainInfoObj.id,
    infeSiteNo: null,
    infeSiteId: null,
    isAlarm: 0,
    alarmText: null
  });

  const url = '/bac-blood-cultrue/findBacBloodCultrueByMaininfoList';
  let data = { maininfoId: labMainInfoObj.id, rptGroup: labMainInfoObj.rptGroup, sampleda: formatDateTime(labMainInfoObj.sampleda, 'yyyy-MM-dd 00:00:00'), sampleNo: labMainInfoObj.sampleNo, testFlowNo: '', testNodeNo: '' } as any;

  proxy.$http
    .get(url, { params: data })
    .then((res: any) => {
      if (res && res.data) {
        let bCultrueList = res.data;
        if (bCultrueList && bCultrueList.length > 0) {
          let bList = bCultrueList.filter((data) => data.isPositive === 0);
          if (bList && bList.length > 0) {
            let germNadesc = '';
            for (const b of bList) {
              germNadesc += b.cultureBottle + ' : ' + b.result + ';';
            }
            bacTestResultForm.germNa = germNadesc.substring(0, germNadesc.length - 1) + '。';
          }
        }
      }
    })
    .catch((err: any) => { });
}
/**页面编辑/切换显示隐藏 */
function editShowModal(item, labmaininfo, isYangXResult = false) {
  isDescOptionResultFlag.value = isYangXResult;
  Object.assign(labMainInfoObj, labmaininfo);
  Object.assign(bacTestResultForm, item);
  isVisiable.value = true;
}
/**判断使用哪个结果选择组件 */
function validateWitchResultComp(row) {
  let res = false;
  if ((IsEmpty(row.id) && IsEmpty(row.germNo)) || (!IsEmpty(row.id) && !isDescOptionResultFlag.value)) {
    res = true;
  }
  return res;
}
/**确认选择 */
function confirmEvent() {
  proxy.$emit('confirmSave', bacTestResultForm);
  isVisiable.value = false;
}
/**关闭窗体 */
function cancelEvent() {
  isVisiable.value = false;
}
/**鉴定结果选中事件 */
function SelectRowClick(e) {
  if (e.isChild) {
    e.aimKeys.forEach((m) => {
      bacTestResultForm[e.childIndex][m.aimKey] = e.row[m.rowKey];
    });
  } else {
    e.aimKeys.forEach((m) => {
      bacTestResultForm[m.aimKey] = e.row[m.rowKey];
    });
  }
}
/**调起模板漂浮div选择框 */
function showTypeCodeDrawer(item, descType) {
  diagnosTempDrawerRef.value.initPage(item, descType);
}
/**判断是否审核，若审核范围ture */
function resultIsDisabled() {
  if (!IsEmpty(labMainInfoObj) && labMainInfoObj.isChk == '2') {
    return true;
  } else {
    return false;
  }
}
/*  */
function selectDiagnosTempInfo() { }
</script>

<style scoped lang="scss">
.custom-radio {
  font-size: 18px;
  cursor: pointer;
  user-select: none;
}
:deep(.vxe-form--item-title .vxe-form--item-title-label) {
  padding-left: 5px;
}
.no-edit {
  user-select: none; /* 禁止选择文本 */
  pointer-events: none; /* 禁止所有鼠标事件 */
}
</style>
